package org.wingstudio.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.wingstudio.entity.File;
import org.wingstudio.entity.News;
import org.wingstudio.entity.ScrollPicture;
import org.wingstudio.entity.Source;
import org.wingstudio.service.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by liao on 16-12-4.
 */

@Controller

public class IndexController {

    @Resource
    private NewsService newsService;
    @Resource
    private FileService fileService;
    @Resource
    private SourceService sourceService;
    @Resource
    private ScrollPictureService scrollPictureService;
    @RequestMapping("index")
    public ModelAndView index(){
        ModelAndView modelAndView=new ModelAndView();
        Map<String,Object> map=new HashMap<String,Object>();
        map.put("start", 0);
        map.put("size", 8);
        map.put("newsTypeId",1);
        List<News> newsList=newsService.list(map);
        News new1=newsList.get(0);
        News new2=newsList.get(1);
        News new3=newsList.get(2);
        List<News> newsList1=new ArrayList<>();
        newsList1.add(new1);
        newsList1.add(new2);
        newsList1.add(new3);
        newsList.remove(0);
        newsList.remove(1);
        newsList.remove(2);
        modelAndView.addObject("newsList1",newsList1);
        modelAndView.addObject("newsList",newsList);


        Map<String,Object> map1=new HashMap<String,Object>();
        map1.put("start", 0);
        map1.put("size", 8);
        map1.put("newsTypeId",2);
        List<News> tenderList1=newsService.list(map1);
        News tender1=tenderList1.get(0);
        News tender2=tenderList1.get(1);
        News tender3=tenderList1.get(2);
        List<News> tenderList=new ArrayList<>();
        tenderList.add(tender1);
        tenderList.add(tender2);
        tenderList.add(tender3);
        tenderList1.remove(0);
        tenderList1.remove(0);
        tenderList1.remove(0);
        modelAndView.addObject("tenderList1",tenderList1);
        modelAndView.addObject("tenderList",tenderList);


        Map<String,Object> map2=new HashMap<String,Object>();
        map2.put("start", 0);
        map2.put("size", 8);
        map2.put("newsTypeId",3);
        List<News> serviceList1=newsService.list(map);
        News service1=serviceList1.get(0);
        News service2=serviceList1.get(1);
        News service3=serviceList1.get(2);
        List<News> serviceList=new ArrayList<>();
        serviceList.add(service1);
        serviceList.add(service2);
        serviceList.add(service3);
        serviceList1.remove(0);
        serviceList1.remove(1);
        serviceList1.remove(2);
        modelAndView.addObject("serviceList1",serviceList1);
        modelAndView.addObject("serviceList",serviceList);
        modelAndView.setViewName("user/index");

        Map<String,Object> map3=new HashMap<String,Object>();
        map3.put("start", 0);
        map3.put("size", 8);
        map3.put("fileTypeId",1);
        List<File> fileList1=fileService.listFile(map3);
        modelAndView.addObject("fileList1",fileList1);

        Map<String,Object> map4=new HashMap<String,Object>();
        map4.put("start", 0);
        map4.put("size", 8);
        map4.put("fileTypeId",2);
        List<File> fileList2=fileService.listFile(map4);
        modelAndView.addObject("fileList2",fileList2);

        Map<String,Object> map5=new HashMap<String,Object>();
        map5.put("start", 0);
        map5.put("size", 8);
        map5.put("fileTypeId",3);
        List<File> fileList3=fileService.listFile(map5);
        modelAndView.addObject("fileList3",fileList3);

        Map<String,Object> map6=new HashMap<String,Object>();
        map6.put("start", 0);
        map6.put("size", 8);
        map6.put("sourceTypeId",1);
        List<Source> sourceList1=sourceService.listSource(map6);
        modelAndView.addObject("sourceList1",sourceList1);

        Map<String,Object> map7=new HashMap<String,Object>();
        map7.put("start", 0);
        map7.put("size", 8);
        map7.put("sourceTypeId",2);
        List<Source> sourceList2=sourceService.listSource(map7);
        modelAndView.addObject("sourceList2",sourceList2);

        List<ScrollPicture> pictures=scrollPictureService.list();
        modelAndView.addObject("picture1",pictures.get(0));
        modelAndView.addObject("picture2",pictures.get(1));
        modelAndView.addObject("picture3",pictures.get(2));
        modelAndView.setViewName("user/index");
        return modelAndView;
    }
}
